import { getAreaObj } from '@/utils/util'

export const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《报名设置信息表》',
							link: true,
							url: 'view_lfRegistrationSettings_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入报名设置信息',
			description: '',
			uploadTip: '报名设置信息表',
			active: 2,
			url: 'view_lfRegistrationSettings_import',
			code: 5002,
			rules: [
				{
					label: '导入规则说明:',
					children: [{ label: '(1)导入模式为“覆盖导入”，待导入的服务对象的信息会覆盖平台已存在的' }],
				},
			],
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '所属区',
			prop: 'areas',
			propName: 'areas_name',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			checkStrictly: false,
			span: 24,
		},
		{
			label: '报名内容',
			prop: 'contentType',
			propName: 'contentTypeLabel',
			type: 'remoteSelect',
			multiple: false,
			code: 'REGISTRATION_CONTENT',
			api: 'getDictItemList',
			span: 24,
			defaultValue: '1',
			disabled: true,
		},
		{
			label: '在街道（镇）办事窗口接受报名',
			prop: 'officeWindowRegistration',
			propName: 'officeWindowRegistrationLabel',
			type: 'remoteSelect',
			multiple: false,
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			span: 24,
		},
		{
			label: '培训形式',
			prop: 'trainingForm',
			propName: 'trainingFormLabel',
			type: 'remoteSelect',
			multiple: true,
			code: 'TRAINING_FORM',
			api: 'getDictItemList',
			span: 24,
		},
		// {
		// 	label: '报名开始日期',
		// 	prop: 'startDate',
		// 	format: 'YYYY年MM月DD日',
		// 	valueFormat: 'YYYY-MM-DD',
		// 	type: 'date',
		// 	span: 12,
		// },
		// {
		// 	label: '报名结束日期',
		// 	prop: 'endDate',
		// 	format: 'YYYY年MM月DD日',
		// 	valueFormat: 'YYYY-MM-DD',
		// 	type: 'date',
		// 	span: 12,
		// },
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'top',
	column: [
		{
			label: '所属区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			checkStrictly: false,
			span: 6,
		},
		{
			label: '在街道（镇）办事窗口接受报名',
			prop: 'officeWindowRegistration',
			propName: 'officeWindowRegistrationLabel',
			type: 'remoteSelect',
			multiple: false,
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			span: 6,
		},
		{
			label: '培训形式',
			prop: 'trainingForm',
			propName: 'trainingFormLabel',
			type: 'remoteSelect',
			multiple: true,
			code: 'TRAINING_FORM',
			api: 'getDictItemList',
			span: 6,
		},
		// {
		// 	label: '报名周期',
		// 	prop: 'startDateBetween',
		// 	format: 'YYYY年MM月DD日',
		// 	valueFormat: 'YYYY-MM-DD HH:mm:ss',
		// 	type: 'dateBetween',
		// 	span: 6,
		// },
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '报名内容', prop: 'contentTypeLabel' },
		{
			label: '在街道（镇）办事窗口接受报名',
			custome: 'tag',
			code: 'COMMON_FLAG',
			prop: 'officeWindowRegistration',
		},
		{
			label: '培训形式',
			prop: 'trainingFormLabel',
		},
		// {
		// 	label: '报名开始日期',
		// 	prop: 'startDate',
		// },
		// {
		// 	label: '报名结束日期',
		// 	prop: 'endDate',
		// },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_lfRegistrationSettings_page',
	add: 'view_lfRegistrationSettings_add',
	edit: 'view_lfRegistrationSettings_edit',
	delete: 'view_lfRegistrationSettings_del',
	import: 'view_lfRegistrationSettings_import',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '报名设置',
	dictcodes: ['COMMON_FLAG', 'REGISTRATION_CONTENT', 'TRAINING_FORM'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'contentTypeLabel',
	exportMqTopic: '/ning/export/',
	importLabel: '导入',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],

	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, '')
			const areasNameObj: any = getAreaObj(form.areas_name, '')
			resolve({
				...form,
				...areasObj,
				...areasNameObj,
				areas: undefined,
			})
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(query.areas, '')
			resolve({
				...query,
				...areasObj,
				areas: undefined,
			})
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item) => {
					const areasObj: any = getAreaObj(item, '', 'set')
					return {
						...item,
						areas_name: areasObj.names,
						areas: areasObj.areaIds,
					}
				})
			)
		})
	},
	dialogConfig: {
		width: '50%',
	},
	searchConfig,
	formConfig,
	detailConfig: formConfig,
	tableConfig,
	importConfig,
}
